package com.freework.tree;

import java.util.Iterator;
import java.util.List;


public class TreeDatas implements  java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5464633975333093563L;
	String text="";
	Integer id=null;
	String code="";
	Integer pid=null;
	String url="";
	String iframe="";
	boolean leaf=true;
	List<TreeDatas> children=null;
	Boolean checked=null;

	
	

	@Override
	public TreeDatas clone(){
		TreeDatas tree= new TreeDatas();
		tree.id=this.id;
		tree.code=this.code;
		tree.pid=this.pid;
		tree.leaf=this.leaf;
		tree.children=this.children;
		tree.url=this.url;
		tree.text=this.text;
		return tree;
	}
	public TreeDatas() {
		 
		 
	 }
		public Integer getPid() {
			return pid;
		}
		public void setPid(Integer pid) {
			this.pid = pid;
		}

	public TreeDatas(Integer id,Integer pid,String text,String url,String code) {
		this.text=text;
		this.id=id;
		this.pid=pid;
		this.url=url;
		this.code=code;
	} 
	public TreeDatas(Integer id,Integer pid,String text,String url,String code,String iframe) {
		this.text=text;
		this.id=id;
		this.pid=pid;
		this.url=url;
		this.code=code;
		this.iframe=iframe;
	} 
	public TreeDatas(Integer id,Integer pid,String text,String code) {
		this.text=text;
		this.id=id;
		this.pid=pid;
		this.code=code;
	} 
	public TreeDatas(Object id,Object pid,String text,String code) {
		this.text=text;
		this.id=Integer.parseInt(id.toString());
		this.pid=Integer.parseInt(pid.toString());
		this.code=code;
	} 
	public TreeDatas(Integer id,Integer pid,String text) {
		this.text=text;
		this.id=id;
		this.pid=pid;
	
	} 
	public List<TreeDatas> getChildren() {
		return children;
	}
	public void setChildren(List<TreeDatas> children) {
		this.children = children;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public boolean isLeaf() {
		return leaf;
	}
	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}



	public String getUrl() {
		return url;
	}

	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	public void setUrl(TreeURL url) {
		this.url = url!=null?url.getURL(this):"";
	}
	
	public void addType(StringBuilder str){
		str.append("id:").append(id).append(",");
		str.append("code:'").append(code).append("',");
		str.append("leaf:").append(leaf).append(",");
		str.append("iframe:'").append(iframe!=null?iframe:"").append("',");
		if(url!=null&&!url.equals(""))
		str.append("url:'").append(url).append("',");
		if(checked!=null&&!checked.equals(""))
			str.append("checked:").append(checked).append(",");
	}
	
	
	public Boolean isChecked() {
		return checked;
	}
	public void setChecked(Boolean checked) {
		this.checked = checked;
	}
	
	public String toString(){
		
		StringBuilder str=new StringBuilder();
		str.append("{");
		
		addType(str);
		if(children!=null&&children.size()>0){
			str.append("children:[");
	        Iterator<TreeDatas> i = children.iterator();
	        boolean hasNext = i.hasNext();
	        while (hasNext) {
	        	TreeDatas tree = i.next();
	            str.append(tree);
	            hasNext = i.hasNext();
	            if (hasNext)
	            	str.append(",");
	        }
	        str.append("],");
		}
		str.append("text:'").append(text).append("'");
		str.append("}");
		return str.toString();
	}
	public String getIframe() {
		return iframe;
	}
	public void setIframe(String iframe) {
		this.iframe = iframe;
	}
	
	
}
